﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace VPL.Mapper
{
    public class Mapper<DomainObject, TransferObject> : IMapper<DomainObject, TransferObject>
        where DomainObject : new()
        where TransferObject : new()
    {
        public Mapper()
        {            
        }

        public IMapper<DomainObject, TransferObject> CreateMap<NestedtDO, NestedDTO>()
        {
            AutoMapper.Mapper.CreateMap<NestedtDO, NestedDTO>();

            return this;
        }

        public TransferObject Map(DomainObject from)
        {
            var map = AutoMapper.Mapper.CreateMap<DomainObject, TransferObject>();
            return AutoMapper.Mapper.Map<DomainObject, TransferObject>(from);
        }

        public DomainObject Map(TransferObject from)
        {
            var map = AutoMapper.Mapper.CreateMap<TransferObject, DomainObject>();
            return AutoMapper.Mapper.Map<TransferObject, DomainObject>(from);
        }

        public IEnumerable<TransferObject> Map(IEnumerable<DomainObject> from)
        {
            var response = new List<TransferObject>();

            if (from != null)
            {
                foreach (var item in from)
                {
                    response.Add(Map(item));
                }                    
            }

            return response;
        }

        public IEnumerable<DomainObject> Map(IEnumerable<TransferObject> from)
        {
            var response = new List<DomainObject>();

            if (from != null)
            {
                foreach (var item in from)
                {
                    response.Add(Map(item));
                }
            }

            return response;
        }
    }
}
